/*
 * VHTabItem.java
 * Created on 24 févr. 2009
 *
 * Glacéo Internet Platform
 * http://sourceforge.net/projects/chm/
 *
 * Copyright (c) 2005-2009, Jens and Jan Janke (VirtualHockey Project)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */

package com.hockeo.vhweb.client.ui.base;

import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.hockeo.vhweb.client.mvc.VHController;


/**
 * Special version of the GXT {@link TabItem} class that adds support for lazy loading of
 * content.
 *
 * @version $Id$
 * @author jjanke
 */
public class VHTabItem extends TabItem
{
  private VHController d_controller;
  private boolean      d_fContentReady = false;

  /**
   * @see TabItem#TabItem()
   */
  public VHTabItem( VHController controller )
  {
    super();
    setLayout( new BorderLayout() );

    d_controller = controller;
  }

  /**
   * @see TabItem#TabItem(String)
   */
  public VHTabItem( VHController controller, String strText )
  {
    super( strText );
    setLayout( new BorderLayout() );

    d_controller = controller;
  }

  /**
   * <p>
   * Builds the content of this tab panel. Any content that should only be rendered the
   * first time when this tab panel is actually shown, should be implemented in this
   * method.
   * </p>
   *
   * <p>
   * This method should be overridden if lazy content building is required. Implementors
   * should only build the content if {@link #isContentReady()} returns <code>false</code>
   * and make sure to correctly set the content as being built by calling this super
   * method at the end of their implementation.
   * </p>
   */
  public void buildContent()
  {
    setContentReady( true );
    layout();
  }

  /**
   * Indicates if the tab item's content has already been built or not.
   */
  protected final boolean isContentReady()
  {
    return d_fContentReady;
  }

  /**
   * Sets whether the tab item's content has been built or not.
   *
   * @param flag <code>true</code> to avoid that the item's content is rebuilt the next
   *          time the tab item is selected, otherwise <code>false</code>
   */
  protected final void setContentReady( boolean flag )
  {
    d_fContentReady = flag;
  }

  /**
   * Returns the associated controller.
   */
  protected final VHController getController()
  {
    return d_controller;
  }
}
